import re,gevent,requests
from threading import Thread
import time


def getimg_path():
    resp=requests.get("http://www.woniuxy.com").text
    li = re.findall("<img src=\"(.+?)\"",resp)
    return li

def download_imgs():
    n=1
    li = getimg_path()
    for i in li:
        img = requests.get(f"http://www.woniuxy.com/{i}").content
        with open(f"./images/img{n}.png", "wb") as f:
            f.write(img)
        n+=1
def download_img(i,n):
    img = requests.get(f"http://www.woniuxy.com/{i}").content
    with open(f"./images/img{n}.png", "wb") as f:
        f.write(img)


if __name__ == '__main__':
    # li = getimg_path()
    # n=1
    # start = time.time()
    # for i in li:
    #     g = gevent.spawn(download_img,i,n)
    #     g.join()
    #     n+=1
    # end=time.time()
    # print(round(end-start,2))

    li = getimg_path()
    m = 1
    t = []
    start = time.time()
    for j in li:
        g = Thread(target=download_img,args=(j,m))
        t.append(g)
        m += 1
    for k in t:
        k.start()
    for k in t:
        k.join()
    end = time.time()
    print(round(end - start, 2))
